package java_class_work.week08.internet.sendStringDemo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author Tiam
 * @Date 2022/11/4 21:06
 * @Description:
 */
public class Client1 {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 8888);
            System.out.println(socket);
            // 开启读取消息的线程, 使其可以一直读取消息
            new Thread(new ClientThread(socket)).start();

            // 输出流 用于向服务端发送消息
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            // 输入流
            Scanner scanner = new Scanner(System.in);
            while (true) {
                // System.out.print("请输入:");
                String message = scanner.nextLine();
                out.println(message);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
